package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/7.
 */
@HttpInlet(Conn.INLET_GET_TRAVEL_BY_DATE)
public class GetTravelByDate extends JTAsyGet<GetTravelByDate.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String obdid = JTApplication.jtPreferences.readOdbID();

    public String date;

    public GetTravelByDate(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parserBody(Object body) {

        Info info = new Info();

        JSONArray array = ((JSONObject)body).optJSONArray("travelList");

        if(array != null){

            for(int i = 0 ; i < array.length() ; i ++){

                JSONObject o = array.optJSONObject(i);

                Travel travel = new Travel();

                travel.END_NAME = o.optString("END_NAME");

                travel.ID = o.optString("ID");

                travel.MILEAGE = o.optString("MILEAGE");

                travel.START_NAME = o.optString("START_NAME");

                travel.START_TIME = o.optString("START_TIME");

                travel.END_TIME = o.optString("END_TIME");

                info.list.add(travel);

            }

        }

        return info;

    }

    public static class Info implements Serializable{

        public List<Travel> list = new ArrayList<>();

    }

    public static class Travel implements Serializable{

        public String END_NAME,MILEAGE,ID ,START_NAME,START_TIME,END_TIME ;

    }

}
